package main

import (
	"fmt"
	"math/rand"
)

func main() {
	var a []int
	for i := 0; i < 10; i++ {
		a = append(a, i)
	}

	fmt.Println(a)

	// expand 扩大slice
	//a = append(a[:4], append(make([]int, 5), a[4:]...)...)
	//fmt.Println(a)

	b := a[:0]
	for _, x := range a {
		if /*f(x)*/ x % 2 == 0 {
			b = append(b, x)
		}
	}
	fmt.Println(a)
	fmt.Println(b)

	// 翻转算法
	for i := len(a)/2-1; i >= 0; i-- {
		opp := len(a)-1-i
		a[i], a[opp] = a[opp], a[i]
	}
	fmt.Println(a)

	// 洗牌算法，打乱一个slice
	for i := len(a) - 1; i > 0; i-- {
		j := rand.Intn(i + 1)
		a[i], a[j] = a[j], a[i]
	}
	fmt.Println(a)
}
